#include "../include/SubmoduleAdd.h"
#include <wx/dirdlg.h>
#include <sdk.h> // Code::Blocks SDK
#include <configurationpanel.h>
#include <logmanager.h>
#include <loggers.h>
#include <projectmanager.h>
#include <cbproject.h>
#include <editormanager.h>
#include <cbeditor.h>
#include <cbstyledtextctrl.h>
#include <wx/sstream.h>
#include <wx/protocol/http.h>
#include <wx/base64.h>
//(*InternalHeaders(SubmoduleAdd)
#include <wx/intl.h>
#include <wx/string.h>
//*)

//(*IdInit(SubmoduleAdd)
const long SubmoduleAdd::ID_STATICTEXT1 = wxNewId();
const long SubmoduleAdd::ID_TEXTCTRL1 = wxNewId();
const long SubmoduleAdd::ID_STATICTEXT2 = wxNewId();
const long SubmoduleAdd::ID_TEXTCTRL2 = wxNewId();
const long SubmoduleAdd::ID_BUTTON1 = wxNewId();
const long SubmoduleAdd::ID_STATICTEXT3 = wxNewId();
const long SubmoduleAdd::ID_TEXTCTRL3 = wxNewId();
//*)

BEGIN_EVENT_TABLE(SubmoduleAdd,wxDialog)
	//(*EventTable(SubmoduleAdd)
	//*)
END_EVENT_TABLE()

SubmoduleAdd::SubmoduleAdd(wxWindow* parent,wxWindowID id,const wxPoint& pos,const wxSize& size)
{
	//(*Initialize(SubmoduleAdd)
	wxBoxSizer* BoxSizer1;
	wxBoxSizer* BoxSizer2;
	wxBoxSizer* BoxSizer3;
	wxBoxSizer* BoxSizer4;
	wxStdDialogButtonSizer* StdDialogButtonSizer1;

	Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T("wxID_ANY"));
	BoxSizer1 = new wxBoxSizer(wxVERTICAL);
	BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
	StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("URL:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
	BoxSizer2->Add(StaticText1, 0, wxALL, 5);
	Url = new wxTextCtrl(this, ID_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
	BoxSizer2->Add(Url, 1, wxALL|wxEXPAND, 5);
	BoxSizer1->Add(BoxSizer2, 1, wxALL|wxEXPAND, 5);
	BoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
	StaticText2 = new wxStaticText(this, ID_STATICTEXT2, _("Path:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2"));
	BoxSizer3->Add(StaticText2, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	Directory = new wxTextCtrl(this, ID_TEXTCTRL2, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL2"));
	BoxSizer3->Add(Directory, 2, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	Borrow = new wxButton(this, ID_BUTTON1, _("Browse"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
	BoxSizer3->Add(Borrow, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	BoxSizer1->Add(BoxSizer3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	BoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
	StaticText3 = new wxStaticText(this, ID_STATICTEXT3, _("Name:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT3"));
	BoxSizer4->Add(StaticText3, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	SubmoduleName = new wxTextCtrl(this, ID_TEXTCTRL3, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL3"));
	BoxSizer4->Add(SubmoduleName, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	BoxSizer1->Add(BoxSizer4, 1, wxALL|wxEXPAND, 5);
	StdDialogButtonSizer1 = new wxStdDialogButtonSizer();
	StdDialogButtonSizer1->AddButton(new wxButton(this, wxID_OK, wxEmptyString));
	StdDialogButtonSizer1->AddButton(new wxButton(this, wxID_CANCEL, wxEmptyString));
	StdDialogButtonSizer1->Realize();
	BoxSizer1->Add(StdDialogButtonSizer1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	SetSizer(BoxSizer1);
	BoxSizer1->Fit(this);
	BoxSizer1->SetSizeHints(this);
	//*)

	Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&SubmoduleAdd::OnBorrowClick);
}

SubmoduleAdd::~SubmoduleAdd()
{
	//(*Destroy(SubmoduleAdd)
	//*)
}


void SubmoduleAdd::OnTextCtrl3Text(wxCommandEvent& event)
{
}

void SubmoduleAdd::OnBorrowClick(wxCommandEvent& event)
{
    wxString dir = Manager::Get()->GetProjectManager()->GetActiveProject()->GetBasePath();
    wxDirDialog dialog(NULL, _("Choose clone directory ..."), dir, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST);
	if(dialog.ShowModal() == wxID_OK)
	{
	    wxString chosePath=dialog.GetPath();
	    if(chosePath.StartsWith(dir)){
            chosePath=chosePath.SubString(dir.length(),chosePath.Length());
	    }
	    else{
            chosePath="";
	    }
		Directory->SetValue(chosePath);
	}

}

void SubmoduleAdd::OnDirectoryText(wxCommandEvent& event)
{
}
